home *** CD-ROM | disk | FTP | other *** search
- /*
- CDIdent - An XFCN to return an unique number identifying this disc
- ©Apple Computer, Inc. 1988
- All Rights Reserved.
-
- 88/11/08 BL°B First Version
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- C -q2 CDIdent.c
- link -sn Main=CDIdent -sn STDIO=CDIdent ∂
- -sn INTENV=CDIdent -rt XFCN=42 ∂
- -m CDIDENT CDIdent.c.o "{CLibraries}"CRuntime.o ∂
- "{CLibraries}"StdCLib.o ∂
- -o HyperCommands
-
- This link directive puts the XCMD in the file "HyperCommands".
- Substitute the name of the stack you want it in. To move XCMDs
- between stacks, use ResEdit. They can be in an individual stack,
- the Home stack, the HyperCard application, or the System File.
-
- */
-
- #include <cd.h>
-
- /* prototype definitions for functions */
- OSErr IDDisc(short, unsigned long *);
- OSErr ReadQ(short, short *, short *, short *, short *);
-
- /* **** WARNING: DO NOT USE GLOBAL VARIABLES! **** */
-
-
- /************************************************************************
- *
- * Function: CDIdent
- *
- * Purpose: return an unique number for this disc.
- *
- * Returns: either the unique number, or an error
- * if it's a negative number, it's an error
- * if we return nothing, wrong number of parameters
- * were specified.
- *
- * Side Effects:
- *
- * Description: We need no parameters
- * Get the ioRefNum that we got from previously calling
- * CDOpen(), by accessing the famous global.
- * call ThisDisc() to get a the lead-out minutes, seconds,
- * and blocks. Add all these together to get the total
- * number of blocks on this disc. This is as unique as
- * we can get, since it's difficult to press two CDs
- * that are equal to 1/75th of a second.
- *
- ************************************************************************/
- pascal void
- CDIdent(paramPtr)
- XCmdBlockPtr paramPtr;
- {
- Str31 returnString;
- OSErr result;
- short ioRefNum;
- Handle refHandle;
- unsigned long discID;
-
- /* Must be no parameter */
- if ((paramPtr->paramCount) != 0)
- {
- /* Report error in parameters by returning -1 */
- NumToStr(paramPtr, -1L, (Str31 *)returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- return;
- }
-
- /* Get the global ioRefNum and convert it. */
- refHandle = GetGlobal(paramPtr, GLOBALNAME);
- ioRefNum = atoi(*(refHandle));
- DisposHandle(refHandle);
- ioRefNum &= 0xFFFF; /* remove vRefNum; not needed. */
-
-
- result = IDDisc(ioRefNum, &discID);
-
- if (result == noErr)
- {
- /* Convert id to string & return it as result */
- NumToStr(paramPtr, discID, (Str31 *)returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) returnString);
- }
- else
- {
- /* We got an error. Convert result to string & return it as error */
- NumToStr(paramPtr, (long) result, (Str31 *)returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) returnString);
- }
- }
-
-
- /************************************************************************
- *
- * Function: IDDisc
- *
- * Purpose: return total time on this disc as unique ID
- *
- * Returns: OSErr
- * either noErr if everything was okay
- * or some parameter error from driver call.
- *
- * Side Effects:
- * fills in discID
- *
- * Description:
- * call the driver ReadTOC call to get lead-out time.
- * Return this time as the unique id for this disc.
- *
- ************************************************************************/
- OSErr
- IDDisc(refNum, discID)
- short refNum;
- unsigned long *discID;
- {
- CDIDParam myPB;
- OSErr result;
-
- myPB.ioCompletion = 0;
- myPB.ioNamePtr = (char *) 0;
- myPB.ioVRefNum = 1;
- myPB.ioCRefNum = refNum;
- myPB.csCode = READTOC;
- myPB.discID = 0x00020000; /* request lead-out time */
-
- result = PBControl((ParmBlkPtr)&myPB, false);
-
- if (result == noErr)
- *discID = myPB.discID >> 8;
- else
- *discID = 0;
- return result;
- }
-
- /* C routines for HyperCard callbacks */
- #include <XCmdGlue.inc.c>
-